package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Wechatuser;
import com.ruoyi.system.service.IWechatuserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公众号用户Controller
 *
 * @author ruoyi
 * @date 2021-05-31
 */
@RestController
@RequestMapping("/system/wechatuser")
public class WechatuserController extends BaseController
{
    @Autowired
    private IWechatuserService wechatuserService;

    /**
     * 查询公众号用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(Wechatuser wechatuser)
    {
        startPage();
        List<Wechatuser> list = wechatuserService.selectWechatuserList(wechatuser);
        return getDataTable(list);
    }

    /**
     * 导出公众号用户列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:export')")
    @Log(title = "公众号用户", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Wechatuser wechatuser)
    {
        List<Wechatuser> list = wechatuserService.selectWechatuserList(wechatuser);
        ExcelUtil<Wechatuser> util = new ExcelUtil<Wechatuser>(Wechatuser.class);
        return util.exportExcel(list, "wechatuser");
    }

    /**
     * 获取公众号用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(wechatuserService.selectWechatuserById(id));
    }

    /**
     * 新增公众号用户
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:add')")
    @Log(title = "公众号用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Wechatuser wechatuser)
    {
        return toAjax(wechatuserService.insertWechatuser(wechatuser));
    }

    /**
     * 修改公众号用户
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:edit')")
    @Log(title = "公众号用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Wechatuser wechatuser)
    {
        return toAjax(wechatuserService.updateWechatuser(wechatuser));
    }

    /**
     * 删除公众号用户
     */
    @PreAuthorize("@ss.hasPermi('system:wechatuser:remove')")
    @Log(title = "公众号用户", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(wechatuserService.deleteWechatuserByIds(ids));
    }
}
